package com.hospital.serviceImpl;

import com.hospital.dao.JurisdictionMapper;
import com.hospital.entity.Jurisdiction;
import com.hospital.entity.RoleJurisdictionVo;
import com.hospital.entity.UserJurisdiction;
import com.hospital.entity.UserJurisdictionVo;
import com.hospital.service.JurisdictionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class JurisdictionServiceImpl implements JurisdictionService {
    @Autowired
    private JurisdictionMapper jurisdictionMapper;

    /**
     * 查所有权限
     *
     * @return 集合中的权限信息
     */
    @Override
    @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
    public List<Jurisdiction> SelectAll() {
        List<Jurisdiction> jurisdictions = jurisdictionMapper.SelectAll();
        return jurisdictions;
    }

    /**
     * 查角色与权限
     *
     * @return 集合中角色与权限信息
     */
    @Override
    public List<RoleJurisdictionVo> SelectRoleJurisdiction() {
        List<RoleJurisdictionVo> roleJurisdictionVos = jurisdictionMapper.SelectRoleJurisdiction();
        return roleJurisdictionVos;
    }

    /**
     * 添加方法
     *
     * @param userJurisdiction 用户与权限实体类
     * @return 添加状态
     */
    @Override
    public Integer Insert(UserJurisdiction userJurisdiction) {
        Integer state = jurisdictionMapper.Insert(userJurisdiction);
        return state;
    }

    /**
     * 删除方法
     *
     * @param id 删除的id
     * @return 删除状态
     */
    @Override
    public Integer BulkDelete(List<Integer> id) {
        Integer state = jurisdictionMapper.BulkDelete(id);
        return state;
    }

    /**
     * 查询用户对应权限的信息
     *
     * @param userId 用户id
     * @return 集合中的用户对应权限的信息
     */
    @Override
    public List<UserJurisdictionVo> SelectByUserJurisdiction(Integer userId) {
        List<UserJurisdictionVo> userJurisdictionVos = jurisdictionMapper.SelectByUserJurisdiction(userId);
        return userJurisdictionVos;
    }
}
